/**
 * @param {number[]} nums
 * @return {number[][]}
 */
var subsetsWithDup = function (nums) {
  nums.sort((a,b)=>a-b)
  let set = new Set()
  let arr = []

  bc(0)

  function bc(index) {
    // if (arr.length != 0) {
    set.add(arr.join(' '))
    // }

    for (let i = index; i < nums.length; i++) {
      arr.push(nums[i])
      bc(i + 1)
      arr.pop()
    }
  }
  let a = [...set.values()].map((item) => {
    if (!item) return []
    else return item.split(' ')
  })
  return [...set.values()].map((item) => {
    if (!item) return []
    else return item.split(' ')
  })
}

subsetsWithDup([4,4,4,1,4])
